package com.example.mardan.views;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;

import com.example.mardan.adapter.CatalogAdapter;
import com.example.mardan.contract.CatalogContract;
import com.example.mardan.entity.CatalogEntity;
import com.example.mardan.presenter.CatalogPresenter;
import com.example.read.databinding.ActivityMainBinding;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements CatalogContract.BookTypeView{
    private ActivityMainBinding binding ;
    private static final String TAG = "MainActivity";
    private CatalogAdapter adapter ;
    private List<CatalogEntity.BookList> bookTypeList ;
    private CatalogContract.BookTypePresenter presenter ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMainBinding.inflate(getLayoutInflater()) ;
        setContentView(binding.getRoot());
        init();
    }

    private void init(){
        presenter = new CatalogPresenter(this,this);
        presenter.gatData("json");
        bookTypeList = new ArrayList<>();
        adapter = new CatalogAdapter(bookTypeList,this);
        binding.mainRecycleView.setLayoutManager(new GridLayoutManager(this , 1));
        binding.mainRecycleView.setAdapter(adapter);
    }


    @Override
    public void showData(CatalogEntity catalogEntity) {
        bookTypeList = catalogEntity.getResult();
        adapter.updateAdapter(bookTypeList);
    }

    @Override
    public void Loading(boolean loading) {

    }

    @Override
    public void Success(Object object) {

    }

    @Override
    public void Fail(String... msg) {

    }

    @Override
    public void Error(String msg) {

    }

    @Override
    public void Complete() {

    }

    @Override
    public void Timeout() {

    }

    @Override
    public void TokenError() {

    }
}